import { createStore, applyMiddleware, combineReducers } from 'redux'
import { ADD_DATA, ADD_SUCCESS, ACTION_ERROR, UPDATE_DATA } from './redux_type'
import thunk  from 'redux-thunk'
import logger  from 'redux-logger'

const initStateRedux1 = {
    msg: "welcome syc",
    status:true
}
const initStateRedux2 = {
    status: false
}
const reduer1 = (state = initStateRedux1, action) => {
    switch (action.type) {
        case ADD_DATA:
            return state
        case ADD_SUCCESS:
            return state
        case ACTION_ERROR:
            return state
        default:
            return state
    }
}
const reduer2 = (state = initStateRedux2, action) => {
    switch (action.type) {
        case ADD_DATA:
            return state
        case ADD_SUCCESS:
            return state
        case ACTION_ERROR:
            return state
        default:
            return state
    }
}
const reducer = (state={}, action) => {
    // console.log("执行了reducer函数");
    // console.log(state, action);

    if (action.type === "set") {
        console.log(action,11111);
        let newState = Object.assign({}, state, action.value)
        return newState
    }else if(action.type === "get"){
        return state
    } else {
        return state
    }
} 
const houseData = (state = {}, action) => {
    switch (action.type) {
        case ADD_DATA:
            let data = Object.assign({}, state, action.data)
            return data
        case UPDATE_DATA:
            let updata = Object.assign({}, state, action.data)
            return updata
        case ADD_SUCCESS:
            return state
        case ACTION_ERROR:
            return state
        default:
            return state
    }
}
const store = createStore(combineReducers({ reduer1, reduer2, houseData,reducer}), applyMiddleware(thunk, logger))

export default store
